package Study0;
import java.sql.SQLOutput;
import java.util.IllegalFormatCodePointException;
import java.util.Scanner;
/*方法的使用探究*/
public class Study2 {
//    方法的重载探究
    /*方法的重载与返回类型无关*/
    /*
    public static void main(String[] args) {

    }
    public static void add(int x,int y) {
        System.out.println("测试");
    }
    public static void add(int num1,int num2) {
        System.out.println("测试");
    }

     */


    /*求顺序的不同*/
    public static void main8 (String[] args) {
        System.out.println("返回类型为double方法的调用的值："+add3(10,10.0));
        System.out.println("返回类型int方法的调用的值："+add3(10.0,10));
    }

    public static double add3 (int x,double y) {
        return x+y;
    }
    public static int add3 (double x,int y) {
        return (int)(x+y);
    }

    /*参数类型的不同*/
    public static void main7 (String[] args) {
        System.out.println("两个浮点数的和:"+add2(10.0,10.0));
        System.out.println("两个整数的和："+add2(10,10));

    }
    /*求两个浮点数的和*/
    public static double add2 (double x,double y) {
        return x+y;
    }
    /*求两个整数的和*/
    public static int add2 (int x,int y) {
        return x+y;
    }




    /*参数的个数的不同*/
    public static void main6 (String[] args) {
        int threeSum = add1(10,10,10);
        System.out.println("三个数值的和 "+threeSum);
        int twoSum = add1(10,10);
        System.out.println("两个数值的和 "+twoSum);
    }
    // 求两个数的和
    public static int add1 (int x,int y) {
        return x+y;
    }
    // 求三个数的和：
    public static int add1 (int x,int y,int z) {
        return x+y+z;
    }



// 实参，形参的关系：交换两个数值
    public static void main5(String[] args) {
        int a = 10;
        int b = 100;
        System.out.println("输出交换之前的数:"+"a ="+a+","+"b ="+b);
        exchangeNum(a,b);
        System.out.println("输出交换之后的数:"+"a ="+a+","+"b ="+b);
    }
    public static void exchangeNum(int num1 ,int num2) {
        int tmp = 0;
        tmp = num2;
        num2 = num1;
        num1 = tmp;
    }



    //    求 1~100 的和
    public static void main4 (String[] args) {
        Study2 study2 = new Study2();
        int sum = study2.sum100(100);
        System.out.println("sum = "+sum);

    }

    public static int sum100 (int n) {
        int sum = 0;
        for (int i = 0; i <= n; i++) {
            sum+=i;
        }
        return sum;
    }



//    求阶乘的二种方法
    public static void main3 (String[] args) {
        Scanner scanner = new Scanner(System.in);
        Study2 study2 = new Study2();
        int n = 0;
        int sum = 0;
        if(scanner.hasNextInt()) {
            n = scanner.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            sum+=study2.fac(i);
        }
        System.out.println("sum = "+sum);
        scanner.close(); // 关闭IO流，代码好风格
    }
    public static int fac(int n) {
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret*=i;
        }
        return ret;
    }



//    求阶乘的一种方法
    public static void main2 (String[] args) {
        Scanner scanner = new Scanner(System.in);
        Study2 study2 = new Study2();
        int n = 0;
        if(scanner.hasNextInt()) {
             n = scanner.nextInt();
        }
        n = study2.factor(n);
        System.out.println(n);
        scanner.close(); // 关闭IO流，代码好风
    }
    public static int factor(int n) {
        int tmp = 1;
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            tmp*=i;
            sum+=tmp;
            if (n == 0) {
                break;
            }
        }
        return sum;
    }
//    两数求和的函数
    public static void main1 (String[] args) {
        Study2 sum = new Study2();
        int num = sum.sum(1,9);
        System.out.println(num);
    }

    public static int sum (int x,int y) {
        return x+y;
    }
}
